import $http from "@/services";
export default {
    state: {
        staffLists: [],
        staffTotal: 0,
        staffDetail: null,
        staffSearch: {
            page: 1,
            size: 5,
            queryData: {}
        }
    },
    // 赋值
    reducers: {
        setStaffLists(state, { payload }) {
            return { ...state, staffLists: payload }
        },
        setStaffTotal(state, { payload }) {
            return { ...state, staffTotal: payload }

        },
        setStaffDetail(state, { payload }) {
            return { ...state, staffDetail: payload }
        },
        setStaffSearch(state, { payload }) {
            return { ...state, staffSearch: { ...state.staffSearch, ...payload } };
        }
    },
    effects: {
        // 初始化数据，获取数据
        *initStaffContent({ payload }, { put, call, select }) {
            // 重新处理请求关系
            yield put({
                type: "setStaffSearch",
                payload
            })
            const { staffSearch } = yield select(state => state.staff);
            //请求数据
            const result = yield call($http.getStaffLists, staffSearch);
            yield put({
                type: "setStaffLists",
                payload: result.data.staffList
            })
            yield put({
                type: "setStaffTotal",
                payload: result.data.staffTotal
            })

        },
        // 重新获取用户详情
        *getDetailStaff({ payload }, { put, call }) {
            const { data } = yield call($http.staffDetail, payload);
            if (data) {
                yield put({
                    type: "setStaffDetail",
                    payload: data
                })
                yield put({
                    type: "common/setIsShowDetail",
                    payload: true
                });
            }

        }
    }
}